package org.example.demo2.mq;

import org.example.demo2.config.RabbitmqConfig;
import org.example.demo2.entity.LikeDTO;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * @ClassName Producer
 * @Description 生产者
 * @Author Kx
 * @Date 2025/10/13 9:48
 * @Version 1.0
 */
@Component
public class Producer {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * @author: kx
     * @date: 2025/10/13 9:50
     * @description: 发送信息
     */
    public void send(LikeDTO likeDTO) {
        // 创建消息唯一ID
        CorrelationData correlationData = new CorrelationData();
        correlationData.setId(UUID.randomUUID().toString());
        // 消息投递
        rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_NAME, RabbitmqConfig.ROUTING_KEY, likeDTO, correlationData);
    }
}
